﻿Friend Class MonitorLock
  Implements IDisposable

  Implements ISharedCollectionLock
  Private _lockStrategy As ExclusiveLockStrategy

  Public Sub New(ByVal lockStrategy As ExclusiveLockStrategy)
    _lockStrategy = lockStrategy
  End Sub

#Region "IDisposable Support"
  Private _isDisposed As Boolean ' To detect redundant calls

  ' IDisposable
  Protected Overridable Sub Dispose(ByVal disposing As Boolean)
    If Not Me._isDisposed Then
      If disposing Then
        _lockStrategy.Exit()
        _lockStrategy = Nothing
      End If

      ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
      ' TODO: set large fields to null.
    End If
    Me._isDisposed = True
  End Sub

  'override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
  'Protected Overrides Sub Finalize()
  '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
  '    Dispose(False)
  '    MyBase.Finalize()
  'End Sub

  ' This code added by Visual Basic to correctly implement the disposable pattern.
  Public Sub Dispose() Implements IDisposable.Dispose
    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
    Dispose(True)
    GC.SuppressFinalize(Me)
  End Sub
#End Region

End Class